/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-06-23
 * 14:14
 */
public class Test {
    public static int removeElement(int[] nums, int val) {
        int j=nums.length-1;
        int i=0;
        for ( i = 0; i <j+1 ; i++) {
            if(nums[i]==val) {
                swap(nums, i, j);
                j--;
                i--;
            }
        }
        return j+1;
    }
    public static void swap(int[] nums,int i,int j){
        int tem=nums[j];
        nums[j]=nums[i];
        nums[i]=tem;
    }

    public static void main(String[] args) {
        int[] nums={3,2,2,3};
        removeElement(nums,3);
        for(int i=0;i<nums.length;i++){
            System.out.println(nums[i]);
        }
        System.out.println(removeElement(nums,3));
    }
}
